package test.yj;

import java.io.IOException;

/**
 * Created by 1emontree on 2017/8/14.
 */
public class OkHttpMain {
    public int getPicture(int i, int k) {
//        int count=0;
//        //i和k控制URL的地址，使得下载50张图片
//        for(int i=0;i<10;i++) {
//            for (int k = 0; k <90; k++) {
        try {
            String url = "http://img.mmjpg.com/2016/65" + i + "/" + k + ".jpg";
            OkHttpDownload okHttp = new OkHttpDownload();
            byte[] b = okHttp.getImg(url);
            if (b == null) {
                throw new Exception();
            }
            if (null != b && b.length > 0) {
                System.out.println("读取到: " + b.length + "字节");
                String filename = "妹子图片" + (55 + i) + "_" + k + ".jpg";
                //int[] array1 = new int[k];
                okHttp.okHttpPictureGet(b, filename);
            }
//                else {
//                }
//                count++;
//                if (count == 50) {
//                    return;
//                }
//            }
//        }
        } catch (Exception e) {
            return 0;
        }
        return 1;
    }

    public static void main(String[] args) throws IOException {
        int count = 0;
        for (int i = 1; i < 10; i++) {
            for (int k = 1; k < 90; k++) {
                int g = new OkHttpMain().getPicture(i, k);
                if (g == 0) {
                    break;
                }
                count++;
                if (count == 50) {
                    return;
                }
            }
        }
    }
}

